<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
    <title>QingCMS后台登录系统</title>
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<link href="res/index.css" rel="stylesheet">
    <link rel="stylesheet" href="../skin/css/font-awesome.min.css">
</head>
<body class="login">
	<div class="htmleaf-container">
			 <h1>顺达费用报销系统</h1>

        <div class="main">
            
		<div class="signin">
			<div class="signin-head"></div>
			<form class="form-signin" role="form">
<div class="input-group margin-bottom-sm">
  <span class="input-group-addon"><i class="fa fa-user"></i></span>
  <input class="form-control" id="username" name="username" placeholder="手机号码" required autofocus>
</div>

<div class="input-group">
  <span class="input-group-addon"><i class="fa  fa-key"></i></span>
  <input class="form-control"  type="password" id="password" name="password" placeholder="请输入密码" required>
</div>
 <div class="input-group">
  <span class="input-group-addon"><i class="fa  fa-image"></i></span>
  <input class="form-control"  type="text" id="code" name="code" placeholder="验证码" style="width:120px" required>
  <img id="codeimg" src="/valcode"  onclick="refresh(this)" />
</div>


				<button class="btn green  btn-block" type="submit">登 &nbsp; 录</button>
<div class="line40"></div>
  <a href="reg.html"><div class="regbtn">注册账号</div></a> 
			</form>

         
		</div>
      </div>
	</div>
	 <script src="res/jquery.min.js"></script>
    <script src="res/md5.min.js"></script>
    <script src="res/cookie.js"></script>
    <script type="text/javascript">

        ajaxurl('/api/islogin', 'get', {}, function succ(data) {
            if (data.status == 1) {
                window.location.href = data.msg;
            }
        });

        $(document).ready(function () {
            $('form').submit(function (event) {
                event.preventDefault();
                var username = $('#username').val(),
                    password = $('#password').val(),
                    code = $('#code').val();
               
                if (username == '') {
                    alert('用户名不能为空');
                    return;
                } else if (password == '') {
                    alert('密码不能为空');
                    return;
                }else if (code == '') {
                    alert('验证码不能为空');
                    return;
                }
                password = md5(password);
                $.ajax({
                    url: '/api/login',
                    type: 'post',
                    dataType: 'json',
                    data: { username: username, password: password,code:code}                
                })
                .done(function (data) {
                    if (data.status == '1') {
                        window.location.href = data.msg;
                    } else {
                        alert(data.msg);
                        refresh('#codeimg');
                    }
                })
                .fail(function (jqXHR) {                  
                        alert('系统错误');                      
                });
            });
        });
    </script>
</body>
</html>